local extension = Package("lvshi_cards", Package.CardPack)
extension.extensionName = "lvshisha"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local ls = require 'packages/lvshisha/utility/lvshi_util'
local U = require "packages/utility/utility"
local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
    ["lvshi_cards"] = "氯师杀牌堆",
    ["nonstrategy"] = "无策略",
    [":nonstrategy"] = "原牌面效果",
  }

local slash = Fk:cloneCard("slash")
local SlashSkill = fk.CreateActiveSkill{
  name = "lvshi__slash_skill",
  prompt = "对对手造成1点伤害",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = slash.skill.onEffect,
}

local Slash = fk.CreateBasicCard{
  name = "lvshi__slash",
  skill = SlashSkill,
  is_damage_card = true,
}

local FireSlashSkill = fk.CreateActiveSkill{
  name = "lvs_fire__slash_skill",
  prompt = "选择攻击范围内的一名角色，对其造成1点火焰伤害",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = "fire__slash_skill",
    })
  end
}

local FireSlash = fk.CreateBasicCard{
  name = "lvs_fire__slash",
  skill = FireSlashSkill,
  is_damage_card = true,
}

local ThunderSlashSkill = fk.CreateActiveSkill{
  name = "lvs_thunder__slash_skill",
  prompt = "选择一名其他角色，对其造成1点雷电伤害",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    return player.id ~= to_select
  end,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    ls.damage(from, to, self.name, 1, fk.ThunderDamage, effect.card)
  end
}

local ThunderSlash = fk.CreateBasicCard{
  name = "lvs_thunder__slash",
  skill = ThunderSlashSkill,
  is_damage_card = true,
}

local iceSlashSkill = fk.CreateActiveSkill{
  name = "lvs_ice__slash_skill",
  prompt = "选择攻击范围内的一名角色，对其造成1点冰冻伤害",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    room:damage({
      from = from,
      to = to,
      damage = 1,
      damageType = fk.IceDamage,
      skillName = self.name,
      card = effect.card,
    })
  end
}

local IceSlash = fk.CreateBasicCard{
  name = "lvs_ice__slash",
  skill = iceSlashSkill,
  is_damage_card = true,
}

extension:addCards{
  Slash:clone(Card.Spade, 4),
  Slash:clone(Card.Spade, 8),
  Slash:clone(Card.Spade, 10),
  Slash:clone(Card.Spade, 12),
  Slash:clone(Card.Heart, 11),
  Slash:clone(Card.Heart, 13),
  Slash:clone(Card.Club, 4),
  Slash:clone(Card.Club, 6),
  Slash:clone(Card.Club, 8),
  Slash:clone(Card.Club, 10),
  Slash:clone(Card.Club, 10),
  Slash:clone(Card.Club, 12),
  Slash:clone(Card.Diamond, 13),

  ThunderSlash:clone(Card.Spade, 5),
  ThunderSlash:clone(Card.Spade, 9),
  ThunderSlash:clone(Card.Spade, 10),
  ThunderSlash:clone(Card.Club, 5),
  ThunderSlash:clone(Card.Club, 9),

  FireSlash:clone(Card.Heart, 7),
  FireSlash:clone(Card.Diamond, 4),
  FireSlash:clone(Card.Diamond, 6),
  FireSlash:clone(Card.Diamond, 12),

  IceSlash:clone(Card.Club, 8),
  IceSlash:clone(Card.Diamond, 5),
}

Fk:loadTranslationTable{
  ["lvshi__slash"] = "杀",
  [":lvshi__slash"] = "<b>基本牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名攻击范围内的角色<br/><b>效果</b>：对目标角色造成1点伤害。",

  ["lvs_fire__slash"] = "火杀",
  [":lvs_fire__slash"] = "<b>基本牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名攻击范围内的角色<br/><b>效果</b>：对目标角色造成1点火焰伤害。",

  ["lvs_thunder__slash"] = "雷杀",
  [":lvs_thunder__slash"] = "<b>基本牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名其他角色<br/><b>效果</b>：对目标角色造成1点雷电伤害。",

  ["lvs_ice__slash"] = "冰杀",
  [":lvs_ice__slash"] = "<b>基本牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名攻击范围内的角色<br/><b>效果</b>：对目标角色造成1点冰冻伤害。", 
}

local jinkSkill = fk.CreateActiveSkill{
  name = "lvshi__jink_skill",
  can_use = Util.FalseFunc,
  on_effect = function(self, room, effect)
    if effect.responseToEvent then
      effect.responseToEvent.isCancellOut = true
    end
  end
}

local jink = fk.CreateBasicCard{
  name = "lvshi__jink",
  skill = jinkSkill,
  is_passive = true,
}

  Fk:loadTranslationTable{
    ["lvshi__jink"] = "闪",
    [":lvshi__jink"] = "<b>基本牌</b></font><br/><b>时机</b>：【杀】对你生效前<br/><b>目标</b>：此【杀】<br/><b>效果</b>：抵消此【杀】。",
  }

  extension:addCards{
    jink:clone(Card.Heart, 2),
    jink:clone(Card.Heart, 5),
    jink:clone(Card.Heart, 7),
    jink:clone(Card.Heart, 9),
    jink:clone(Card.Heart, 10),
    jink:clone(Card.Diamond, 2),
    jink:clone(Card.Diamond, 7),
    jink:clone(Card.Diamond, 7),
    jink:clone(Card.Diamond, 8),
    jink:clone(Card.Diamond, 8),
    jink:clone(Card.Diamond, 9),
    jink:clone(Card.Diamond, 10),
    jink:clone(Card.Diamond, 11),
    jink:clone(Card.Diamond, 11),
  }

local peach = Fk:cloneCard("peach")

local peachSkill = fk.CreateActiveSkill{
  name = "lvshi__peach_skill",
  prompt = "#peach_skill",
  mod_target_filter = peach.skill.modTargetFilter,
  target_filter = peach.skill.targetFilter,
  can_use = peach.skill.canUse,
  on_use = peach.skill.onUse,
  on_effect = peach.skill.onEffect,
}

local peach = fk.CreateBasicCard{
  name = "lvshi__peach",
  skill = peachSkill,
}

extension:addCards{
  peach:clone(Card.Heart, 4),
  peach:clone(Card.Heart, 6),
  peach:clone(Card.Heart, 8),
  peach:clone(Card.Heart, 9),
  peach:clone(Card.Heart, 10),
  peach:clone(Card.Diamond, 2),
  peach:clone(Card.Diamond, 6),
  peach:clone(Card.Diamond, 10),
}  

Fk:loadTranslationTable{
  ["lvshi__peach"] = "桃",
  ["lvshi__peach_skill"] = "桃",
  [":lvshi__peach"] = "<b>基本牌</b></font><br/><b>时机：</b>出牌阶段。<br/>"..
  "<b>目标：</b>包括你在内的一名已受伤的角色（如无特殊说明只能对自己使用）。<br/><b>效果：</b>目标角色回复1点体力。<br/>"..
  "<b>使用方法②</b><br/><b>时机：</b>当一名角色处于濒死状态时。<br/><b>目标：</b>一名处于濒死状态的角色。<br/>"..
  "<b>效果：</b>目标角色回复1点体力。<br/>",
}

local analeptic = Fk:cloneCard("analeptic")

local analepticSkill = fk.CreateActiveSkill{
  name = "analeptic_skill",
  max_turn_use_time = 1,
  mod_target_filter = analeptic.skill.modTargetFilter,
  target_filter = analeptic.skill.targetFilter,
  can_use = analeptic.skill.canUse,
  on_use = analeptic.skill.onUse,
  on_effect = analeptic.skill.onEffect,
}

local analeptic = fk.CreateBasicCard{
  name = "lvshi__analeptic",
  skill = analepticSkill,
}

extension:addCards{
  analeptic:clone(Card.Spade, 9),
  analeptic:clone(Card.Club, 9),
  analeptic:clone(Card.Diamond, 9),
}

Fk:loadTranslationTable{
  ["lvshi__analeptic"] = "酒",
  [":lvshi__analeptic"] = "<b>基本牌</b></font><br/><b>时机：</b>出牌阶段。<br/>"..
  "<b>目标：</b>包括你在内的一名角色（如无特殊说明只能对自己使用）。<br/><b>效果：</b>你于此回合使用的下一张【杀】造成的伤害值基数+1。<br/>"..
  "<b>使用方法②</b><br/><b>时机：</b>当你处于濒死状态时。<br/><b>目标：</b>你。<br/>"..
  "<b>效果：</b>目标角色回复1点体力。<br/>",
}

local pearAction = fk.CreateTriggerSkill{
  name = "#lvshi__pear_action",
  priority = 0.1,
  global = true,
  events = {fk.AfterCardsMove},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player.phase == Player.Play or player.dead then return end
    for _, move in ipairs(data) do
      if move.from and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if info.fromArea == Card.PlayerHand and Fk:getCardById(id).trueName == "pear" then
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_trigger = function(self, event, target, player, data)
    player.room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
  end,
}

Fk:addSkill(pearAction)

local pearSkill = fk.CreateActiveSkill{
  name = "lvshi__pear_skill",
  prompt = "选择一名其他角色，其回复1点体力",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return target ~= player and target:isWounded()
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    room:recover({
      who = target,
      num = 1,
      card = effect.card,
      recoverBy = player,
      skillName = self.name
    })
  end
}

local pear = fk.CreateBasicCard{
  name = "lvshi__pear",
  skill = pearSkill,
}

Fk:addSkill(pearSkill)

extension:addCards{
  pear:clone(Card.Heart, 3),
  pear:clone(Card.Diamond, 3),
}

Fk:loadTranslationTable{
  ["pear"] = "梨",
  ["lvshi__pear"] = "梨",
  [":lvshi__pear"] = "<b>基本牌</b></font><br/><b>时机：</b>出牌阶段。<br/>"..
  "<b>目标：</b>一名已受伤的其他角色。<br/><b>效果：</b>目标角色回复1点体力。<br/>"..
  "<b>固有效果</b>：锁定技，当【梨】离开你的手牌区后，若不为你的出牌阶段，你回复1点体力。",
  [":#lvshi__pear_action"] = "梨",
}

local poisonAction = fk.CreateTriggerSkill{
  name = "#lvshi_poison_action",
  global = true,
  --priority = 0.1,
  events = {fk.AfterCardsMove},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    local poison_losehp = (data.extra_data or {}).lvshi_poison_losehp or {}
    return table.contains(poison_losehp, player.id) and table.every(player.room.alive_players, function(p) return not p.dying end)
  end,
  on_trigger = function(self, event, target, player, data)
    local poison_losehp = (data.extra_data or {}).lvshi_poison_losehp or {}
    player.room:notifySkillInvoked(player, self.name, "negative")
    player.room:loseHp(player, #table.filter(poison_losehp, function(pid) return pid == player.id end), "lvshi_poison")
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        return player.room.current and player.room.current == player
      end
    end
    return false
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if move.toArea == Card.DiscardPile then
          local id = info.cardId
          if Fk:getCardById(id).name == "lvshi_poison" then
            data.extra_data = data.extra_data or {}
            local poison_losehp = data.extra_data.lvshi_poison_losehp or {}
            table.insert(poison_losehp, player.id)
            data.extra_data.lvshi_poison_losehp = poison_losehp
          end
        end
      end
    end
  end,
}

Fk:addSkill(poisonAction)

local poisonSkill = fk.CreateActiveSkill{
  name = "lvshi_poison_skill",
  prompt = "选择一名距离1的角色，其失去1点体力"..
  "<br /><font color=\"#F0E68C\"><b>此牌进入弃牌堆后当前回合角色失去1点体力！</b></font>",
  max_phase_use_time = 1,
  distance_limit = 1,
  target_num = 1,
  can_use = function(self, player, card)
    return self:withinTimesLimit(player, Player.HistoryPhase, card, "lvshi_poison", player)
  end,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local player = Fk:currentRoom():getPlayerById(to_select)
    return user ~= player and not (distance_limited and not self:withinDistanceLimit(user, false, card, player))
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    room:loseHp(target, 1, "lvshi_poison")
  end
}

local poison = fk.CreateBasicCard{
  name = "lvshi_poison",
  skill = poisonSkill,
}

extension:addCards{
  poison:clone(Card.Spade, 3),
  poison:clone(Card.Club, 3),
}  

Fk:loadTranslationTable{
  ["lvshi_poison"] = "毒",
  [":lvshi_poison"] = "<b>基本牌</b><br /><b>时机</b>：出牌阶段限一次<br /><b>目标</b>：距离为1的一名其他角色<br /><b>效果</b>：目标角色失去1点体力。<br /><b>固有效果</b>：锁定技，当此牌置入弃牌堆后，当前回合角色失去1点体力。",
  ["#lvshi_poison_action"] = "毒",
}

local function strategylog(player, card, strategy)
  player.room:sendLog{
    type = "#strategyuse",
    from = player.id,
    arg = card:toLogString(),
    arg2 = strategy,
    toast = true,
  }
end

local function strategytrickuse(room, use, cardname, scheme, courage)
  if use.card:isVirtual() and not use.card.canstrategy then return "nonstrategy" end
  local player = room:getPlayerById(use.from)
  local choices = {"nonstrategy"}
  if string.find(ls.getStrategy(player), "scheme") then table.insert(choices, scheme) end
  if string.find(ls.getStrategy(player), "courage") then table.insert(choices, courage) end
  local choice = room:askForChoice(player, choices, cardname, "", true)
  local strategy = "none"
  if choice == scheme then
    strategy = "scheme"
  elseif choice == courage then
    strategy = "courage"
  end
  if strategy ~= "none" then
    strategylog(player, use.card, strategy)
  end
  return choice
end

Fk:loadTranslationTable{
  ["scheme"] = "智策略",
  ["courage"] = "勇策略",
  ["#strategyuse"] = "%from 发动了 %arg 的 %arg2 效果",
}

local dismantlement = Fk:cloneCard("dismantlement")

local lvs__dismantlementSkill = fk.CreateActiveSkill{
  name = "lvshi__dismantlement_skill",
  prompt = "#dismantlement_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = dismantlement.skill.modTargetFilter,
  target_filter = dismantlement.skill.targetFilter,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "dismantlement", "dismantlement_scheme", "dismantlement_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if from.dead or to.dead or to:isAllNude() then return end
    local id
    if effect.extra_data.strategy == "dismantlement_scheme" then
      local cards = {}
      if to:getHandcardNum() > 0 then table.insertIfNeed(cards, {"$Hand", to:getCardIds("h")}) end
      if #to:getCardIds("e") > 0 then table.insertIfNeed(cards, {"$Equip", to:getCardIds("e")}) end
      if #to:getCardIds("j") > 0 then table.insertIfNeed(cards, {"$Judge", to:getCardIds("j")}) end
      id = room:askForCardChosen(from, to, { card_data = cards }, "dismantlement")
    else
      id = room:askForCardChosen(from, to, "hej", "dismantlement")
    end
    room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, "dismantlement_skill", nil, true, effect.from)
    if effect.extra_data.strategy == "dismantlement_courage" then
      if from:distanceTo(to) == 1 and Fk:getCardById(id).color == effect.card.color then
        room:delay(200)
        room:moveCardTo(id, Card.PlayerHand, from, fk.ReasonJustMove, self.name, nil, true, effect.from)
      end
    end
  end
}
local lvs__dismantlement = fk.CreateTrickCard{
  name = "lvshi__dismantlement",
  skill = lvs__dismantlementSkill,
}

extension:addCards({
  lvs__dismantlement:clone(Card.Spade, 4),
  lvs__dismantlement:clone(Card.Spade, 7),
  lvs__dismantlement:clone(Card.Heart, 4),
  lvs__dismantlement:clone(Card.Club, 4),
})

local snatch = Fk:cloneCard("snatch")
local lvs__snatchSkill = fk.CreateActiveSkill{
  name = "lvshi__snatch_skill",
  prompt = "#snatch_skill",
  can_use = Util.CanUse,
  distance_limit = 1,
  mod_target_filter = snatch.skill.modTargetFilter,
  target_filter = snatch.skill.targetFilter,
  target_num = 1,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "snatch", "snatch_scheme", "snatch_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if from.dead or to.dead or to:isAllNude() then return end
    if effect.extra_data.strategy == "snatch_scheme" then
      local cards = {}
      if to:getHandcardNum() > 0 then table.insertIfNeed(cards, {"$Hand", to:getCardIds("h")}) end
      if #to:getCardIds("e") > 0 then table.insertIfNeed(cards, {"$Equip", to:getCardIds("e")}) end
      if #to:getCardIds("j") > 0 then table.insertIfNeed(cards, {"$Judge", to:getCardIds("j")}) end
      local id = room:askForCardChosen(from, to, { card_data = cards }, "snatch")
      room:obtainCard(from, id, false, fk.ReasonPrey)
      DIY.ShowCards(from, id)
      local card = Fk:getCardById(id)
      if card.trueName == "jink" or card.trueName == "peach" then
        to:drawCards(2, self.name)
      end
    else
      if effect.extra_data.strategy == "snatch_courage" or effect.card:getMark("strategycourage") > 0 then
        local hidden = ls.gethidecards(to)
        if #hidden > 0 then
          local id = table.random(hidden, 1)
          DIY.ShowCards(to, id)
        end
      end
      local cid = room:askForCardChosen(from, to, "hej", "snatch")
      room:obtainCard(from, cid, false, fk.ReasonPrey)
      if effect.extra_data.strategy == "snatch_courage" or effect.card:getMark("strategycourage") > 0 then
        local card = Fk:getCardById(cid)
        if card.trueName == "slash" or card.name == "lvshi_poison" then
          from:turnOver()
          room:useVirtualCard(card.name, nil, from, to, self.name, true)
        end
      end
    end
  end
}

local lvs__snatch = fk.CreateTrickCard{
  name = "lvshi__snatch",
  skill = lvs__snatchSkill,
}

extension:addCards({
  lvs__snatch:clone(Card.Spade, 6),
  lvs__snatch:clone(Card.Club, 12),
  lvs__snatch:clone(Card.Diamond, 4),
})

Fk:loadTranslationTable{
  ["lvshi__dismantlement"] = "过河拆桥",
  [":lvshi__dismantlement"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名区域里有牌的其他角色。<br /><b>效果</b>：你弃置目标角色区域里的一张牌。"..
  "<br /><b>智策略效果</b>：你先观看目标角色的手牌。<br /><b>勇策略效果</b>：若你与目标角色距离为1且弃置的牌与此牌颜色相同，你获得之。",
  ["dismantlement_scheme"] = "智策略",
  [":dismantlement_scheme"] = "你先观看目标角色的手牌",
  ["dismantlement_courage"] = "勇策略",
  [":dismantlement_courage"] = "若你与目标角色距离为1且弃置的牌与此牌颜色相同，你获得之",

  ["lvshi__snatch"] = "顺手牵羊",
  [":lvshi__snatch"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：距离为1的一名区域里有牌的其他角色。<br /><b>效果</b>：你获得目标角色区域里的一张牌。"..
  "<br /><b>智策略效果</b>：你先观看目标角色的手牌，若你获得【闪】或【桃】，你明置之，其摸两张牌。<br /><b>勇策略效果</b>：你先明置目标角色一张手牌，若你获得【杀】或【毒】，你翻面，视为对目标角色使用之。",
  ["snatch_scheme"] = "智策略",
  [":snatch_scheme"] = "你先观看目标角色的手牌，若你获得【闪】或【桃】，其摸两张牌",
  ["#recourse-give"] = "请交给%src一张牌",
  ["snatch_courage"] = "勇策略",
  [":snatch_courage"] = "你先明置目标角色一张手牌，若你获得【杀】或【毒】，你翻面，视为对目标角色使用之",
}

local duel = Fk:cloneCard("duel")

local lvs__duelSkill = fk.CreateActiveSkill{
  name = "lvshi__duel_skill",
  prompt = "#duel_skill",
  mod_target_filter = duel.skill.modTargetFilter,
  target_filter = duel.skill.targetFilter,
  target_num = 1,
  can_use = duel.skill.canUse,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "duel", "duel_scheme", "duel_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = duel.skill.onEffect,
}

local lvs__duel = fk.CreateTrickCard{
  name = "lvshi__duel",
  skill = lvs__duelSkill,
  is_damage_card = true,
}

extension:addCards{
  lvs__duel:clone(Card.Spade, 1),
  lvs__duel:clone(Card.Club, 2),
}

local lvs__duel_effect = fk.CreateTriggerSkill{
  name = "#lvs__duel_effect",
  frequency = Skill.Compulsory,
  global = true,
  mute = true,
  refresh_events = {fk.TargetSpecified},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card.name == "lvshi__duel"
    and data.extra_data and data.extra_data.strategy ~= "nonstrategy"
  end,
  on_refresh = function(self, event, target, player, data)
    if data.extra_data.strategy == "duel_scheme" then
      local n = 0
      for _, v in pairs(target.cardUsedHistory) do
        if v[Player.HistoryTurn] > 0 then
          n = n + v[Player.HistoryTurn]
          if n > 1 then return end
        end
      end
      if n == 1 then
        data.disresponsive = true
      end
    end
    if data.extra_data.strategy == "duel_courage" then
      if player:getHandcardNum() <= player.room:getPlayerById(data.to):getHandcardNum() then
        data.additionalDamage = (data.additionalDamage or 0) + 1
      end
    end
  end,
}

Fk:addSkill(lvs__duel_effect)

Fk:loadTranslationTable{
  ["lvshi__duel"] = "决斗",
  [":lvshi__duel"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色<br /><b>效果</b>：由目标角色开始，其与你轮流打出【杀】，直到其中一名角色未打出【杀】。然后未打出【杀】的角色受到另一名角色对其造成的1点伤害。"..
  "<br /><b>智策略效果</b>：若为此回合使用的第一张牌，则目标角色不可响应。<br /><b>勇策略效果</b>：若你的手牌数不大于目标角色，则此牌造成的伤害+1。",
  ["duel_scheme"] = "智策略",
  [":duel_scheme"] = "若为此回合使用的第一张牌，则目标角色不可响应",
  ["duel_courage"] = "勇策略",
  [":duel_courage"] = "若你的手牌数不大于目标角色，则此牌造成的伤害+1",
}

local fireAttackSkill = fk.CreateActiveSkill{
  name = "lvshi__fire_attack_skill",
  prompt = "#fire_attack_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function(_, to_select, _, _, _, _)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return not to:isKongcheng()
  end,
  target_filter = Util.TargetFilter,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "fire_attack", "fire_attack_scheme", "fire_attack_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if to:isKongcheng() then return end
    local hidden = ls.gethidecards(to)
    if #hidden > 0 then
      if effect.extra_data.strategy == "fire_attack_scheme" then
        DIY.ShowCards(to, hidden)
      else
        local showCard = room:askForCard(to, 1, 1, false, self.name, false, tostring(Exppattern{ id = hidden }), "#fire_attack-show:" .. from.id)[1]
        DIY.ShowCards(to, showCard)
      end
    end
    local suits = {}
    for _, id in ipairs(DIY.GetShownCards(to)) do
      local suit = Fk:getCardById(id):getSuitString()
      table.insertIfNeed(suits,suit)
    end
    local cards = room:askForDiscard(from, 1, 1, true, "fire_attack_skill", true,  ".|.|" .. table.concat(suits, ","), "#lvshi__fire_attack-throw:"..to.id)
    if #cards > 0 then
      ls.damage(from, to, self.name, 1, fk.FireDamage, effect.card)
    elseif (effect.extra_data.strategy == "fire_attack_courage" or effect.card:getMark("strategycourage") > 0)
    and #DIY.GetShownCards(to) > 0 then
      local to_give = room:askForCard(to, 1, 1, false, self.name, false, tostring(Exppattern{ id = DIY.GetShownCards(to) }), "#lvshi__fire_attack-give:" .. from.id)
      room:moveCardTo(to_give, Card.PlayerHand, from, fk.ReasonGive, self.name, nil, false, effect.from)
    end
  end,
}

local fireAttack = fk.CreateTrickCard{
  name = "lvshi__fire_attack",
  skill = fireAttackSkill,
  is_damage_card = true,
}

extension:addCards{
  fireAttack:clone(Card.Heart, 2),
  fireAttack:clone(Card.Diamond, 3),
}

Fk:loadTranslationTable{
  ["lvshi__fire_attack"] = "火攻",
  [":lvshi__fire_attack"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名有手牌的角色<br /><b>效果</b>：目标角色明置一张手牌，然后你可弃置一张与其明置手牌花色相同的牌，对其造成1点火焰伤害。"..
  "<br /><b>智策略效果</b>：目标角色明置所有手牌。<br /><b>勇策略效果</b>：若你未弃置牌，目标交给你一张明置牌。",
  ["#lvshi__fire_attack-throw"] = "你可以弃置一张与%src明置牌花色相同的牌，对其造成1点火焰伤害",
  ["fire_attack_scheme"] = "智策略",
  [":fire_attack_scheme"] = "目标角色明置所有手牌",
  ["fire_attack_courage"] = "勇策略",
  [":fire_attack_courage"] = "若你未弃置牌，目标交给你一张明置牌",
  ["#lvshi__fire_attack-give"] = "请交给%src一张明置牌",
}

local exNihiloSkill = fk.CreateActiveSkill{
  name = "lvshi__ex_nihilo_skill",
  prompt = "#ex_nihilo_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "ex_nihilo", "ex_nihilo_scheme", "ex_nihilo_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
    if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
      use.tos = { { use.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    if target.dead then return end
    if effect.extra_data.strategy == "ex_nihilo_scheme" then
      room:askForGuanxing(target, room:getNCards(2), nil, nil)
    end
    target:drawCards(2, "ex_nihilo")
    if effect.extra_data.strategy == "ex_nihilo_courage" then
      target:drawCards(1, "ex_nihilo")
      local discards = room:askForDiscard(target, 1, 1, true, self.name, true, ".|.|.|.|.|^basic", "#addtroops_throw")
      if #discards == 0 then
        room:askForDiscard(target, 2, 2, false, self.name, true)
      end
    end
  end
}

local exNihilo = fk.CreateTrickCard{
  name = "lvshi__ex_nihilo",
  skill = exNihiloSkill,
}

extension:addCards({
  exNihilo:clone(Card.Heart, 3),
  exNihilo:clone(Card.Heart, 11),
})

Fk:loadTranslationTable{
  ["lvshi__ex_nihilo"] = "无中生有",
  [":lvshi__ex_nihilo"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：包括你在内的一名角色。<br /><b>效果</b>：目标角色摸两张牌。"..
  "<br /><b>智策略效果</b>：你先卜算2。<br /><b>勇策略效果</b>：你额外摸一张牌，然后选择弃置一张非基本牌或两张牌。",
  ["ex_nihilo_scheme"] = "智策略",
  [":ex_nihilo_scheme"] = "你先卜算2",
  ["ex_nihilo_courage"] = "勇策略",
  [":ex_nihilo_courage"] = "你额外摸一张牌，然后选择弃置一张非基本牌或两张牌",
  ["#befriend-choose"] = "请选择一张手牌和一名距离大于1的角色",
  ["#addtroops_throw"] = "请选择一张非基本牌弃置，否则你须弃置两张牌",
}

local DrowningSkill = fk.CreateActiveSkill{
  name = "lvshi__drowning_skill",
  prompt = "选择一名其他角色，其须弃置两张非基本牌，否则受到1点伤害",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    return to_select ~= player.id
  end,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "drowning", "drowning_scheme", "drowning_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    local discards = room:askForDiscard(to, 2, 2, true, "lvshi__drowning", true, ".|.|.|.|.|^basic", "#lvs__drowning:"..effect.from)
    if #discards == 0 then
      if effect.extra_data.strategy == "drowning_scheme" then
        room:damage({
          from = from,
          to = to,
          damage = 1,
          damageType = fk.IceDamage,
          skillName = self.name,
          card = effect.card,
        })
      else
        ls.damage(room:getPlayerById(effect.from), to, self.name, 1, fk.NormalDamage, effect.card)
      end
    elseif effect.extra_data.strategy == "drowning_courage" then
      local targets = table.map(room:getOtherPlayers(to), Util.IdMapper)
      local tos, ids = room:askForChooseCardsAndPlayers(from, 1, 1, targets, 1, 1, ".", "#drowning-obtain", "lvshi__drowning", false)
      if #tos > 0 then
        room:moveCardTo(ids, Card.PlayerHand, to, fk.ReasonPrey, "lvshi__drowning", nil, false, effect.from)
        room:moveCardTo(discards, Card.PlayerHand, room:getPlayerById(tos[1]), fk.ReasonJustMove, "lvshi__drowning", nil, true)
      end
    end
  end,
}

local Drowning = fk.CreateTrickCard{
  name = "lvshi__drowning",
  skill = DrowningSkill,
  is_damage_card = true,
}

extension:addCards({
  Drowning:clone(Card.Club, 7),
})

Fk:loadTranslationTable{
  ["lvshi__drowning"] = "水淹七军",
  [":lvshi__drowning"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色<br /><b>效果</b>：目标角色选择一项：弃置两张非基本牌，或受到你造成的1点伤害。"..
  "<br /><b>智策略效果</b>：造成的伤害为冰冻伤害。<br /><b>勇策略效果</b>：你可交给目标角色一张牌，令另一名角色获得其弃置的牌。",
  ["#lvs__drowning"] = "请弃置两张非基本牌，否则受到%src造成的1点伤害",
  ["drowning_scheme"] = "智策略",
  [":drowning_scheme"] = "造成的伤害为冰冻伤害",
  ["drowning_courage"] = "勇策略",
  [":drowning_courage"] = "你可交给目标角色一张牌，令另一名角色获得其弃置的牌",
  ["#drowning-obtain"] = "请选择交给目标角色的牌和获得弃置牌的角色",
}

local RockfallSkill = fk.CreateActiveSkill{
  name = "lvshi__rockfall_skill",
  prompt = "选择一名没有手牌或横置的角色，其失去1点体力",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return target:isKongcheng() or target.chained
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    room:loseHp(to, 1, self.name)
  end,
}

local Rockfall = fk.CreateTrickCard{
  name = "lvshi__rockfall",
  skill = RockfallSkill,
}

extension:addCards({
  Rockfall:clone(Card.Spade, 11),
  Rockfall:clone(Card.Club, 11),
})

Fk:loadTranslationTable{
  ["lvshi__rockfall"] = "落井下石",
  [":lvshi__rockfall"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名武将牌横置或没有手牌的角色<br /><b>效果</b>：目标角色失去1点体力。",
}

local SupportSkill = fk.CreateActiveSkill{
  name = "lvshi__support_skill",
  prompt = "选择一名角色，其将牌堆顶牌置为护甲，然后若其手牌数为场上最小，其摸一张牌",
  target_num = 1,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      to:addToPile("shield", room:getNCards(1), false, self.name)
      if table.every(room:getOtherPlayers(to), function (p) return p:getHandcardNum() >= to:getHandcardNum() end) then
        to:drawCards(1, "support")
      end
  end,
}

local Support = fk.CreateTrickCard{
  name = "lvshi__support",
  skill = SupportSkill,
  suit = Card.Club,
  number = 1,
}

extension:addCard(Support)

Fk:loadTranslationTable{
  ["lvshi__support"] = "援护",
  ["lvshi__support_skill"] = "援护",
  [":lvshi__support"] = "普通锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名角色<br /><b>效果</b>：目标角色将牌堆顶牌置为<a href='lvs__shield'>护甲</a>，然后若其手牌数为场上最小，其摸一张牌。",
}

local nullificationSkill = fk.CreateActiveSkill{
  name = "lvshi__nullification_skill",
  can_use = Util.FalseFunc,
  on_effect = function(self, room, effect)
    if effect.responseToEvent then
      effect.responseToEvent.isCancellOut = true
    end
  end
}
local nullification = fk.CreateTrickCard{
  name = "lvshi__nullification",
  skill = nullificationSkill,
  is_passive = true,
}

extension:addCards({
  nullification:clone(Card.Spade, 13),
  nullification:clone(Card.Heart, 13),
  nullification:clone(Card.Club, 13),
  nullification:clone(Card.Diamond, 13),
})

Fk:loadTranslationTable{
  ["lvshi__nullification"] = "无懈可击",
  ["lvshi__nullification_skill"] = "无懈可击",
  [":lvshi__nullification"] = Fk:translate(":nullification"),
}

local CollaborateSkill = fk.CreateActiveSkill{
  name = "lvshi__collaborate_skill",
  prompt = "选择一至两名有手牌的角色，明置或暗置一张手牌",
  max_target_num = 2,
  min_target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card)
    return not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  target_filter = Util.TargetFilter,
  on_action = function(self, room, use, finished)
    if finished then
      local cards = {}
      for _, p in ipairs(room.alive_players) do
        table.insertTable(cards, DIY.GetShownCards(p))
      end
      if #cards > 1 and table.every(cards, function(id) return Fk:getCardById(cards[1]).color == Fk:getCardById(id).color end) then
        room:getPlayerById(use.from):drawCards(2, "lvshi__collaborate")
      end
    end
  end,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if from.dead or to.dead then return end
    local cid = room:askForCardChosen(from, to, "h", "lvshi__collaborate")
    if cid then
      if table.contains(ls.gethidecards(to), cid) then
        DIY.ShowCards(to, cid)
      else
        DIY.HideCards(to, cid)
      end
    end
  end,
}

local Collaborate = fk.CreateTrickCard{
  name = "lvshi__collaborate",
  skill = CollaborateSkill,
  multiple_targets = true,
}

extension:addCards({
  Collaborate:clone(Card.Heart, 12),
})

Fk:loadTranslationTable{
  ["lvshi__collaborate"] = "里应外合",
  [":lvshi__collaborate"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一至两名有手牌的角色。<br /><b>效果</b>：你明置或暗置目标角色的一张手牌，最后若所有角色的明置手牌颜色相同且总数不小于两张，你摸两张牌。",
}

local ironChainCardSkill = fk.CreateActiveSkill{
  name = "lvshi__iron_chain_skill",
  prompt = "#iron_chain_skill",
  can_use = Util.CanUse,
  min_target_num = 1,
  max_target_num = 2,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.TargetFilter,
  on_effect = function(_, room, cardEffectEvent)
    local to = room:getPlayerById(cardEffectEvent.to)
    to:setChainState(not to.chained)
  end,
}

local ironChain = fk.CreateTrickCard{
  name = "lvshi__iron_chain",
  skill = ironChainCardSkill,
  special_skills = { "recast" },
  multiple_targets = true,
}

extension:addCards{
  ironChain:clone(Card.Spade, 3),
  ironChain:clone(Card.Club, 3),
  ironChain:clone(Card.Club, 13),
}

Fk:loadTranslationTable{
  ["lvshi__iron_chain"] = "铁索连环",
  [":lvshi__iron_chain"] = Fk:translate(":iron_chain")
}

local lureTigerSkill = fk.CreateActiveSkill{
  name = "lvshi__lure_tiger_skill",
  prompt = "#lvshi__lure_tiger_skill",
  can_use = Util.CanUse,
  min_target_num = 1,
  max_target_num = 2,
  mod_target_filter = function(self, to_select, selected, player)
    return player.id ~= to_select
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    --[[room:setPlayerMark(target, "@@lure_tiger-turn", 1)
    room:setPlayerMark(target, MarkEnum.PlayerRemoved .. "-turn", 1)
    room:handleAddLoseSkills(target, "#lvshi__lure_tiger_prohibit", nil, false, true)]]
    DIY.removePlayer(target, "-turn")
    room.logic:trigger("fk.RemoveStateChanged", target, nil) -- FIXME
  end,
}

local lureTigerProhibit = fk.CreateProhibitSkill{
  name = "#lvshi__lure_tiger_prohibit",
  is_prohibited = function(self, from, to, card)
    if from ~= to then
      return from:getMark("@@lure_tiger-turn") > 0 or to:getMark("@@lure_tiger-turn") > 0 
    end
  end,
}

Fk:addSkill(lureTigerProhibit)

local lureTiger = fk.CreateTrickCard{
  name = "lvshi__lure_tiger",
  skill = lureTigerSkill,
  suit = Card.Spade,
  number = 13,
  multiple_targets = true,
  special_skills = { "recast" },
}

extension:addCard(lureTiger)

Fk:loadTranslationTable{
  ["lvshi__lure_tiger"] = "调虎离山",
  [":lvshi__lure_tiger"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一至两名其他角色<br/><b>效果</b>：目标角色于此回合内<a href='lvs__leave'>调离</a>。",
  ["#lvshi__lure_tiger_prohibit"] = "调虎离山",
  ["#lvshi__lure_tiger_skill"] = "选择一至两名其他角色，这些角色于此回合内调离",
  ["lvs__leave"] = "调离的角色不计入距离和座次的计算，且不能使用牌指定其他角色，不是其他角色使用牌的合法目标。",
  ["@@lure_tiger-turn"] = "调离",
}

local awaitExhaustedSkill = fk.CreateActiveSkill{
  name = "lvshi__await_exhausted_skill",
  prompt = "#lvshi__await_exhausted_skill",
  mod_target_filter = function(self, to_select, selected, user)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return target == user or ls.isFriend(user, target)
  end,
  can_use = function(self, player, card)
    if player:prohibitUse(card) then return end
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if not player:isProhibited(p, card) and self:modTargetFilter(p.id, {}, player, card, true) then
        return true
      end
    end
  end,
  on_use = function(self, room, use)
    if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
      local player = room:getPlayerById(use.from)
      if not player.role_shown then
        use.tos = {{use.from}}
      else
        use.tos = {}
        for _, p in ipairs(room:getAlivePlayers()) do
          if not player:isProhibited(p, use.card) and ls.isFriend(player, p) then --权宜
            TargetGroup:pushTargets(use.tos, p.id)
          end
        end
      end
    end
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    if target.dead then return end
    target:drawCards(2, "lvshi__await_exhausted")
    if target.dead then return end
      room:askForDiscard(target, 2, 2, true, self.name, false)
  end,
}

local awaitExhausted = fk.CreateTrickCard{
  name = "lvshi__await_exhausted",
  skill = awaitExhaustedSkill,
  multiple_targets = true,
}

extension:addCards({
  awaitExhausted:clone(Card.Club, 11),
})

Fk:loadTranslationTable{
  ["lvshi__await_exhausted"] = "以逸待劳",
  ["lvshi__await_exhausted_skill"] = "以逸待劳",
  [":lvshi__await_exhausted"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你和与你阵营相同的角色<br/><b>效果</b>：每名目标角色各摸两张牌，"..
  "然后弃置两张牌。",
  ["#lvshi__await_exhausted_skill"] = "你和与你阵营相同的角色各摸两张牌，然后弃置两张牌",
}

local savage_assault = Fk:cloneCard("savage_assault")
local archery_attack = Fk:cloneCard("archery_attack")
local god_salvation = Fk:cloneCard("god_salvation")

local savageAssaultSkill = fk.CreateActiveSkill{
  name = "lvs__savage_assault_skill",
  prompt = "#savage_assault_skill",
  can_use = Util.AoeCanUse,
  on_use = Util.AoeOnUse,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    return to_select ~= player.id
  end,
  on_effect = savage_assault.skill.onEffect,
}

local savageAssault = fk.CreateTrickCard{
  name = "lvs__savage_assault",
  skill = savageAssaultSkill,
  multiple_targets = true,
  is_damage_card = true,
}

extension:addCards({
  savageAssault:clone(Card.Spade, 7),
  savageAssault:clone(Card.Club, 7),
})

local archeryAttackSkill = fk.CreateActiveSkill{
  name = "lvs__archery_attack_skill",
  prompt = "#archery_attack_skill",
  can_use = Util.AoeCanUse,
  on_use = Util.AoeOnUse,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    return to_select ~= player.id
  end,
  on_effect = archery_attack.skill.onEffect,
}

local archeryAttack = fk.CreateTrickCard{
  name = "lvs__archery_attack",
  skill = archeryAttackSkill,
  suit = Card.Heart,
  number = 1,
  multiple_targets = true,
  is_damage_card = true,
}

extension:addCard(archeryAttack)

local GodSalvationSkill = fk.CreateActiveSkill{
  name = "lvs__god_salvation_skill",
  prompt = "#god_salvation_skill",
  can_use = Util.GlobalCanUse,
  on_use = Util.GlobalOnUse,
  mod_target_filter = Util.TrueFunc,
  about_to_effect = function(self, room, effect)
    if not room:getPlayerById(effect.to):isWounded() then
      return true
    end
  end,
  on_effect = god_salvation.skill.onEffect,
}

local GodSalvation = fk.CreateTrickCard{
  name = "lvs__god_salvation",
  skill = GodSalvationSkill,
  suit = Card.Heart,
  number = 1,
  multiple_targets = true,
  is_damage_card = true,
}

extension:addCard(GodSalvation)

Fk:loadTranslationTable{
  ["lvs__savage_assault"] = "南蛮入侵",
  [":lvs__savage_assault"] = "普通锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：所有其他角色<br /><b>效果</b>：每名目标角色须打出一张【杀】，否则受到1点伤害。",
  ["lvs__archery_attack"] = "万箭齐发",
  [":lvs__archery_attack"] = "普通锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：所有其他角色<br /><b>效果</b>：每名目标角色须打出一张【闪】，否则受到1点伤害。",
  ["lvs__god_salvation"] = "桃园结义",
  [":lvs__god_salvation"] = "普通锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：所有角色<br /><b>效果</b>：每名目标角色回复1点体力。",
}

local indulgenceSkill = fk.CreateActiveSkill{
  name = "lvshi__indulgence_skill",
  prompt = "#lvshi__indulgence_skill",
  can_use = Util.CanUse,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    return player.id ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card, extra_data, player)
    if not Util.TargetFilter(self, to_select, selected, _, card, extra_data, player) then return end
    return #selected == 0 and self:modTargetFilter(to_select, selected, player, card, true)
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local judge = {
      who = to,
      reason = "indulgence",
      pattern = ".|.|spade,club,diamond",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit == Card.Heart then
      room:addPlayerMark(to, "MinusMaxCards-turn", 1)
    else
      room:addPlayerMark(to, "AddMaxCards-turn", 1)
      to:skip(Player.Play)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = function(self, room, effect)
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse
    }
  end,
}

local indulgence = fk.CreateDelayedTrickCard{
  name = "lvshi__indulgence",
  suit = Card.Heart,
  number = 6,
  skill = indulgenceSkill,
}

extension:addCard(indulgence)

local supplyShortageSkill = fk.CreateActiveSkill{
  name = "lvshi__supply_shortage_skill",
  prompt = "#lvshi__supply_shortage_skill",
  can_use = Util.CanUse,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card, extra_data, player)
    if not Util.TargetFilter(self, to_select, selected, _, card, extra_data, player) then return end
    return #selected == 0 and self:modTargetFilter(to_select, selected, player, card, true)
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local judge = {
      who = to,
      reason = "supply_shortage",
      pattern = ".|.|spade,heart,diamond",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit == Card.Club then
      room:handleAddLoseSkills(to, "#supply_shortage_attackrange", nil, false, true)
      room:addPlayerMark(to, "supply_shortage-turn")
    else
      to:skip(Player.Draw)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = function(self, room, effect)
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse
    }
  end,
}

local supply_shortage_attackrange = fk.CreateAttackRangeSkill{
  name = "#supply_shortage_attackrange",
  correct_func = function (self, from, to)
    if from:getMark("supply_shortage-turn") > 0 then
      return -2
    end
  end,
}

Fk:addSkill(supply_shortage_attackrange)

local supplyShortage = fk.CreateDelayedTrickCard{
  name = "lvshi__supply_shortage",
  suit = Card.Club,
  number = 6,
  skill = supplyShortageSkill,
}

Fk:loadTranslationTable{
  ["lvshi__indulgence"] = "乐不思蜀",
  [":lvshi__indulgence"] = "<b>延时锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色。<br /><b>效果</b>：将此牌置于目标角色判定区内。其判定阶段进行判定，若结果不为♥，其跳过出牌阶段且此回合手牌上限+1，否则此回合手牌上限-1。",
  ["#lvshi__indulgence_skill"] = "选择一名角色，将此牌置于其判定区内。其判定阶段判定：<br />若结果不为♥，其跳过出牌阶段",

  ["lvshi__supply_shortage"] = "兵粮寸断",
  [":lvshi__supply_shortage"] = "<b>延时锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色。<br /><b>效果</b>：将此牌置于目标角色判定区内。其判定阶段进行判定：若结果不为♣，其跳过摸牌阶段，否则此回合攻击范围-2。",
  ["#lvshi__supply_shortage_skill"] = "选择一名角色，将此牌置于其判定区内。其判定阶段判定：<br />若结果不为♣，其跳过摸牌阶段",
}

extension:addCard(supplyShortage)

local lightning = Fk:cloneCard("lightning")

local lightningSkill = fk.CreateActiveSkill{
  name = "lvshi__lightning_skill",
  prompt = "#lvshi__lightning_skill",
  can_use = Util.CanUse,
  mod_target_filter = Util.TrueFunc,
  target_filter = function(self, to_select, selected, _, card, extra_data, player)
    if not Util.TargetFilter(self, to_select, selected, _, card, extra_data, player) then return end
    return #selected == 0 and self:modTargetFilter(to_select, selected, player, card, true)
  end,
  target_num = 1,
  on_effect = lightning.skill.onEffect,
  on_nullified = lightning.skill.onNullified,
}

local lightning = fk.CreateDelayedTrickCard{
  name = "lvshi__lightning",
  suit = Card.Spade,
  number = 12,
  skill = lightningSkill,
}

extension:addCard(lightning)

Fk:loadTranslationTable{
  ["lvshi__lightning"] = "闪电",
  [":lvshi__lightning"] = "<b>延时锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名角色。<br /><b>效果</b>：目标角色判定，若结果为黑桃2-9，则其受到3点无来源雷电伤害，将此牌置入弃牌堆。否则将此牌置入其下家的判定区（若其下家不为此牌的合法目标，则顺延至其下家的下家，以此类推）。",
  ["#lvshi__lightning_skill"] = "选择一名角色，将【闪电】置入其判定区",
}

local lvshi__crossbowSkill = fk.CreateTargetModSkill{
  name = "#lvshi__crossbow_skill",
  attached_equip = "lvshi__crossbow",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self.name) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return 3
    end
  end,
}

--lvshi__crossbowSkill:addRelatedSkill("#crossbowAudio")
Fk:addSkill(lvshi__crossbowSkill)

local lvshi__crossbow = fk.CreateWeapon{
  name = "lvshi__crossbow",
  suit = Card.Diamond,
  number = 1,
  attack_range = 2,
  equip_skill = lvshi__crossbowSkill,
}

extension:addCard(lvshi__crossbow)

Fk:loadTranslationTable{
  ["lvshi__crossbow"] = "连弩",
  [":lvshi__crossbow"] = "装备牌·武器<br /><b>攻击范围</b>：2 <br/><b>武器技能</b>：锁定技，你使用【杀】的次数上限+3。",
  ["#lvshi__crossbow_skill"] = "连弩",
}

local gudingSkill = fk.CreateTriggerSkill{
  name = "#lvshi__guding_blade_skill",
  attached_equip = "lvshi__guding_blade",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, _, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      return data.by_user and (data.to:isKongcheng() or table.every(player.room:getOtherPlayers(data.to), function (p)
        return p.hp > data.to.hp end))
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:broadcastPlaySound("./packages/maneuvering/audio/card/guding_blade")
    player.room:setEmotion(player, "./packages/maneuvering/image/anim/guding_blade")
    data.damage = data.damage + 1
  end,
}
Fk:addSkill(gudingSkill)
local gudingBlade = fk.CreateWeapon{
  name = "lvshi__guding_blade",
  suit = Card.Spade,
  number = 1,
  attack_range = 2,
  equip_skill = gudingSkill,
}

extension:addCard(gudingBlade)

Fk:loadTranslationTable{
  ["lvshi__guding_blade"] = "古锭刀",
  [":lvshi__guding_blade"] =  "装备牌·武器<br /><b>攻击范围</b>：2<br /><b>武器技能</b>：当你使用【杀】对目标角色造成伤害时，若其没有手牌或体力值为唯一最小，此伤害+1。",
  ["#lvshi__guding_blade_skill"] = "古锭刀",
}

local lvshi__ice_swordSkill = fk.CreateTriggerSkill{
  name = "#lvshi__ice_sword_skill",
  attached_equip = "lvshi__ice_sword",
  events = {fk.AfterCardUseDeclared, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
        return target == player and player:hasSkill(self.name) and (data.card.name == "slash" or data.card.name == "lvshi__slash")
    else
        return target == player and player:hasSkill(self.name) and string.find(data.card.name, "ice__slash") and not data.card:isVirtual()
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      return player.room:askForSkillInvoke(player, self.name, nil, "#icesword-invoke")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:broadcastPlaySound("./packages/standard_cards/audio/card/ice_sword")
    player.room:setEmotion(player, "./packages/standard_cards/image/anim/ice_sword")
    if event == fk.AfterCardUseDeclared then
      local iceSlash = Fk:cloneCard("ice__slash")
      table.insertIfNeed(iceSlash.skillNames, "ice_sword")
      iceSlash:addSubcard(data.card)
      player.room:sendLog{
        type = "#lvshi__ice_sword",
        from = player.id,
        arg = data.card:toLogString(),
        arg2 = iceSlash:toLogString(),
        toast = true,
      }
      data.card = iceSlash
    else
      data.disresponsive = true
    end
  end,
}

Fk:addSkill(lvshi__ice_swordSkill)

local lvshi__ice_sword = fk.CreateWeapon{
  name = "lvshi__ice_sword",
  suit = Card.Spade,
  number = 2,
  attack_range = 2,
  equip_skill = lvshi__ice_swordSkill,
}

extension:addCard(lvshi__ice_sword)

Fk:loadTranslationTable{
  ["lvshi__ice_sword"] = "寒冰剑",
  ["#lvshi__ice_sword_skill"] = "寒冰剑",
  [":lvshi__ice_sword"] = "装备牌·武器<br /><b>攻击范围</b>：2<br /><b>武器技能</b>：当你使用普通【杀】时，可将之视为冰【杀】，你使用非转化/视为的冰【杀】指定目标后，令之不可被响应。",
  ["#icesword-invoke"] = "你可将此【杀】视为冰【杀】",
  ["#lvshi__ice_sword"] = "%from 将 %arg 视为 %arg2",
}

local doubleSwordsSkill = fk.CreateTriggerSkill{
  name = "#lvshi__double_swords_skill",
  attached_equip = "lvshi__double_swords",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      return string.find(data.card.name, "fire") or string.find(data.card.name, "thunder")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:broadcastPlaySound("./packages/standard_cards/audio/card/double_swords")
    player.room:setEmotion(player, "./packages/standard_cards/image/anim/double_swords")
    local to = player.room:getPlayerById(data.to)
    if to:isNude() then
      player:drawCards(1, self.name)
    else
      local result = room:askForDiscard(to, 1, 1, true, self.name, true, ".", "#ls__double_swords-invoke:"..player.id)
      if #result == 0 then
        player:drawCards(1, self.name)
      end
    end
  end,
}
Fk:addSkill(doubleSwordsSkill)
local doubleSwords = fk.CreateWeapon{
  name = "lvshi__double_swords",
  suit = Card.Spade,
  number = 8,
  attack_range = 2,
  equip_skill = doubleSwordsSkill,
}

extension:addCard(doubleSwords)

Fk:loadTranslationTable{
  ["lvshi__double_swords"] = "鸾凤和鸣剑",
  ["#lvshi__double_swords_skill"] = "鸾凤和鸣剑",
  [":lvshi__double_swords"] = "装备牌·武器<br /><b>攻击范围</b>：2<br /><b>武器技能</b>：当你使用火【杀】或雷【杀】指定目标后，你可令目标角色弃置一张牌，否则你摸一张牌。",
  ["#ls__double_swords-invoke"] = "请弃置一张牌，否则%src摸一张牌",
}

local ls_spear_slash = fk.CreateTriggerSkill{
  name = "#ls_spear&",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      return target == player and data.card.trueName == "slash" and data.card.skillName == "spear"
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:broadcastPlaySound("./packages/standard_cards/audio/card/spear")
    player.room:setEmotion(player, "./packages/standard_cards/image/anim/spear")
    data.fixedResponseTimes = data.fixedResponseTimes or {}
    local n = 1
    for _, id in ipairs(data.card.subcards) do
      if Fk:getCardById(id).trueName == "slash" then
        n = n + 1
      end
    end
    data.fixedResponseTimes["jink"] = n
  end,
}

local spearSkill = fk.CreateViewAsSkill{
  name = "lvshi__spear_skill&",
  prompt = "#spear_skill",
  attached_equip = "spear",
  pattern = "slash",
  card_filter = function(self, to_select, selected)
    if #selected == 2 then return false end
    return table.contains(Self:getHandlyIds(true), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then
      return nil
    end
    local c = Fk:cloneCard("slash")
    c.skillName = "spear"
    c:addSubcards(cards)
    return c
  end,
}

spearSkill:addRelatedSkill(ls_spear_slash)
Fk:addSkill(spearSkill)

local spear = fk.CreateWeapon{
  name = "lvshi__spear",
  suit = Card.Club,
  number = 5,
  attack_range = 3,
  equip_skill = spearSkill,
}

extension:addCard(spear)

Fk:loadTranslationTable{
  ["lvshi__spear"] = "丈八蛇矛",
  [":lvshi__spear"] = "装备牌·武器<br /><b>攻击范围</b>：3<br /><b>武器技能</b>：你可将两张手牌当【杀】使用或打出，以此法转化的牌每有一张【杀】，则额外需要一张【闪】抵消。",
  ["lvshi__spear_skill&"] = "丈八蛇矛",
  [":lvshi__spear_skill&"] = "你可将两张手牌当【杀】使用或打出，以此法转化的牌每有一张【杀】，则额外需要一张【闪】抵消。",
  ["#ls_spear&"] = "丈八蛇矛",
}

local halberdTargets = fk.CreateActiveSkill{
  name = "#lvshi__halberd_targets",
  can_use = Util.FalseFunc,
  min_target_num = 1,
  max_target_num = 2,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, _, _, _, player)
    local orig = table.simpleClone(player:getMark("_lvshi__halberd"))
    if table.contains(orig, to_select) or to_select == player.id then return false end
    local target = Fk:currentRoom():getPlayerById(to_select)
    local card = Fk:cloneCard("slash")
    return not player:isProhibited(target, card) and card.skill:modTargetFilter(to_select, orig, player, card, true)
  end,
}
local halberdDelay = fk.CreateTriggerSkill{
  name = "#lvshi__halberd_delay",
  mute = true,
  events = {fk.CardEffectCancelledOut},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and (player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data[1].extra_data or {}).saHalberd
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    local use = e.data[1]
    if #TargetGroup:getRealTargets(use.tos) > 0 then
      room:sendLog{
        type = "#HalberdNullified",
        from = target.id,
        arg = "lvshi__halberd",
        arg2 = data.card:toLogString(),
      }
      use.nullifiedTargets = TargetGroup:getRealTargets(use.tos)
    end
  end,
}

local halberdSkill = fk.CreateTriggerSkill{
  name = "#lvshi__halberd_skill",
  attached_equip = "lvshi__halberd",
  events = {fk.AfterCardTargetDeclared},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and #player.room:getUseExtraTargets(data) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "_lvshi__halberd", TargetGroup:getRealTargets(data.tos))
    local _, ret = room:askForUseActiveSkill(player, "#lvshi__halberd_targets", "#lvshi__halberd-ask", true)
    room:setPlayerMark(player, "_lvshi__halberd", 0)
    if ret then
      self.cost_data = ret.targets
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/standard_cards/audio/card/halberd")
    room:setEmotion(player, "./packages/standard_cards/image/anim/halberd")
    room:doIndicate(player.id, self.cost_data)
    data.extra_data = data.extra_data or {}
    data.extra_data.saHalberd = true
    data.card.skillName = "lvshi__halberd"
    room:sendLog{
      type = "#HalberdTargets",
      from = player.id,
      to = self.cost_data,
      arg = "lvshi__halberd",
      card = Card:getIdList(data.card),
    }
    table.forEach(self.cost_data, function (id)
      table.insert(data.tos, {id})
    end)
  end
}

halberdSkill:addRelatedSkill(halberdTargets)
halberdSkill:addRelatedSkill(halberdDelay)
Fk:addSkill(halberdSkill)

local halberd = fk.CreateWeapon{
  name = "lvshi__halberd",
  suit = Card.Diamond,
  number = 12,
  attack_range = 4,
  equip_skill = halberdSkill,
}

extension:addCard(halberd)

Fk:loadTranslationTable{
  ["lvshi__halberd"] = "方天画戟",
  [":lvshi__halberd"] = "装备牌·武器<br /><b>攻击范围</b>：4<br /><b>武器技能</b>：当你使用【杀】选择目标后，"..
  "可以令至多两名其他角色也成为目标，当此【杀】被【闪】抵消后，此【杀】对所有目标均无效。",
  ["#lvshi__halberd_skill"] = "方天画戟",
  ["#lvshi__halberd_targets"] = "方天画戟",
  ["#lvshi__halberd-ask"] = "你可发动〖方天画戟〗，令至多两名角色也成为目标",
  ["#lvshi__halberd_delay"] = "方天画戟",
  ["#HalberdTargets"] = "%from 发动了〖%arg〗，令 %to 也成为 %card 的目标",
  ["#HalberdNullified"] = "由于〖%arg〗的效果，%from 对所有剩余目标使用的 %arg2 无效",
}

local lvshi__fanSkill = fk.CreateTriggerSkill{
  name = "#lvshi__fan_skill",
  attached_equip = "lvshi__fan",
  events = {fk.AfterCardUseDeclared, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
        return target == player and player:hasSkill(self.name) and (data.card.name == "slash" or data.card.name == "lvshi__slash")
    else
        return target == player and player:hasSkill(self.name) and data.card and string.find(data.card.name, "fire__slash") and not data.card:isVirtual()
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      return player.room:askForSkillInvoke(player, self.name, nil, "#fans-invoke")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:broadcastPlaySound("./packages/maneuvering/audio/card/fan")
    player.room:setEmotion(player, "./packages/maneuvering/image/anim/fan")
    if event == fk.AfterCardUseDeclared then
      local fireSlash = Fk:cloneCard("fire__slash")
      table.insertIfNeed(fireSlash.skillNames, "fan")
      fireSlash:addSubcard(data.card)
      player.room:sendLog{
        type = "#lvshi__fan",
        from = player.id,
        arg = data.card:toLogString(),
        arg2 = fireSlash:toLogString(),
        toast = true,
      }
      data.card = fireSlash
    else
      data.damage = data.damage + 1
    end
  end,
}

Fk:addSkill(lvshi__fanSkill)

local fan = fk.CreateWeapon{
  name = "lvshi__fan",
  suit = Card.Diamond,
  number = 12,
  attack_range = 4,
  equip_skill = lvshi__fanSkill,
}

extension:addCard(fan)
Fk:loadTranslationTable{
  ["lvshi__fan"] = "朱雀羽扇",
  ["#lvshi__fan_skill"] = "朱雀羽扇",
  [":lvshi__fan"] = "装备牌·武器<br /><b>攻击范围</b>：4<br /><b>武器技能</b>：当你使用普通【杀】时，可将之视为火【杀】，你使用非转化/视为的火【杀】造成伤害时，令之+1。",
  ["#fans-invoke"] = "你可将此【杀】视为火【杀】",
  ["#lvshi__fan"] = "%from 将 %arg 视为 %arg2",
}

local niohShieldSkill = fk.CreateTriggerSkill{
  name = "#lvshi__nioh_shield_skill",
  attached_equip = "lvshi__nioh_shield",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    return player.id == data.to and player:hasSkill(self) and data.card.trueName == "slash" and data.card.color == Card.Black
  end,
  on_use = function(self, event, _, player, data)
    player.room:broadcastPlaySound("./packages/standard_cards/audio/card/nioh_shield")
    player.room:setEmotion(player, "./packages/standard_cards/image/anim/nioh_shield")
    return true
  end,
}

Fk:addSkill(niohShieldSkill)

local niohShield = fk.CreateArmor{
  name = "lvshi__nioh_shield",
  suit = Card.Club,
  number = 2,
  equip_skill = niohShieldSkill,
}

extension:addCards({
  niohShield,
})

Fk:loadTranslationTable{
  ["lvshi__nioh_shield"] = "仁王盾",
  ["#lvshi__nioh_shield_skill"] = "仁王盾",
  [":lvshi__nioh_shield"] = Fk:translate(":nioh_shield"),
}

local silverLionSkill = fk.CreateTriggerSkill{
  name = "#lvshi__silver_lion_skill",
  attached_equip = "lvshi__silver_lion",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self) and data.damage > 1
    else
      if player.dead or not player:isWounded() then return false end
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerEquip and Fk:getCardById(info.cardId).name == self.attached_equip then
              return self:isEffectable(player)
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, _, player, data)
    player.room:broadcastPlaySound("./packages/maneuvering/audio/card/silver_lion")
    player.room:setEmotion(player, "./packages/maneuvering/image/anim/silver_lion")
    if event == fk.DamageInflicted then
      data.damage = 1
    else
      local room = player.room
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}

Fk:addSkill(silverLionSkill)

local silverLion = fk.CreateArmor{
  name = "lvshi__silver_lion",
  suit = Card.Club,
  number = 2,
  equip_skill = silverLionSkill,
}

extension:addCard(silverLion)

Fk:loadTranslationTable{
  ["lvshi__silver_lion"] = "白银狮子",
  [":lvshi__silver_lion"] = Fk:translate(":silver_lion"),
  ["#lvshi__silver_lion_skill"] = "白银狮子",
}

local ls__vineSkill = fk.CreateTriggerSkill{
  name = "#lvshi__vine_skill",
  attached_equip = "lvshi__vine",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then
      return target == player and player:hasSkill(self) and data.damageType == fk.FireDamage
    else
      local names = {"drowning", "savage_assault", "archery_attack"}
      return player.id == data.to and player:hasSkill(self) and (data.card.name == "slash" or data.card.name == "lvshi__slash"
      or table.contains(names, data.card.trueName))
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      room:broadcastPlaySound("./packages/maneuvering/audio/card/vineburn")
      room:setEmotion(player, "./packages/maneuvering/image/anim/vineburn")
      if player:getEquipment(Card.SubtypeArmor) then
        room:moveCardTo(player:getEquipment(Card.SubtypeArmor), Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil, true, player.id)
      end
      if not player.dead then
        room:loseHp(player, 1, self.name)
      end
    else
      room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
      room:setEmotion(player, "./packages/maneuvering/image/anim/vine")
      return true
    end
  end,
}

Fk:addSkill(ls__vineSkill)

local vine = fk.CreateArmor{
  name = "lvshi__vine",
  equip_skill = ls__vineSkill,
  suit = Card.Spade,
  number = 5,
}

extension:addCard(vine)
Fk:loadTranslationTable{
["lvshi__vine"] = "藤甲",
["#lvshi__vine_skill"] = "藤甲",
[":lvshi__vine"] = "装备牌·防具<br /><b>防具技能</b>：锁定技。【南蛮入侵】、【万箭齐发】、【水淹七军】和普通【杀】对你无效。当你受到火焰伤害后，你弃置装备区内的【藤甲】并失去1点体力。",
}

local brightArmorSkill = fk.CreateTriggerSkill{
  name = "#lvshi__bright_armor_skill",
  attached_equip = "lvshi__bright_armor",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirming, fk.BeforeChainStateChange},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) then return false end
    if event == fk.TargetConfirming then
      local names = {"fire__slash", "thunder__slash", "ice__slash", "fire_attack", "unexpectation"}
      return table.find(names, function (name) return string.find(data.card.name, name) end)
    else
      return not player.chained
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then 
      AimGroup:cancelTarget(data, player.id)
    end
    return true
  end
}
Fk:addSkill(brightArmorSkill)

local brightArmor = fk.CreateArmor{
  name = "lvshi__bright_armor",
  suit = Card.Spade,
  number = 2,
  equip_skill = brightArmorSkill,
}
extension:addCard(brightArmor)
Fk:loadTranslationTable{
  ["lvshi__bright_armor"] = "明光铠",
  ["#lvshi__bright_armor_skill"] = "明光铠",
  [":lvshi__bright_armor"] = "装备牌·防具<br/><b>防具技能</b>：锁定技，当你成为【火攻】,【出其不意】或属性【杀】的目标时，你取消此目标；当你横置前，你防止之。",
}

local PosterSkill = fk.CreateDistanceSkill{
  name = "#lvs__poster_skill",
  attached_equip = "lvs__poster",
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      if #from:getCardIds("e") <= 2 then
        return -2
      else
        return -1
      end
    end
  end,
}

local Poster = fk.CreateOffensiveRide{
  name = "lvs__poster",
  suit = Card.Spade,
  number = 6,
  equip_skill = PosterSkill,
}
Fk:addSkill(PosterSkill)
extension:addCard(Poster)

Fk:loadTranslationTable{
  ["lvs__poster"] = "驿马",
  ["#lvs__poster_skill"] = "驿马",
  [":lvs__poster"] = "装备牌·进攻类坐骑<br /><b>坐骑技能</b>：锁定技，你与其他角色的距离-1，若你的装备区内牌数量不大于2，则额外-1。",
}

local Chitutrigger = fk.CreateTriggerSkill{
  name = "#lvshi__chitu_trigger",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash"
    and (data.card.suit == Card.Heart or (data.card.color == Card.Red and player:getEquipment(Card.SubtypeWeapon)))
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsive = true
  end,
}

local ChituSkill = fk.CreateDistanceSkill{ 
  name = "#lvs__chitu_skill",
  attached_equip = "lvs__chitu",
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
  end,
}

local Chitu = fk.CreateOffensiveRide{
  name = "lvs__chitu",
  suit = Card.Heart,
  number = 5,
  equip_skill = ChituSkill,
}

ChituSkill:addRelatedSkill(Chitutrigger)
Fk:addSkill(ChituSkill)
extension:addCard(Chitu)

Fk:loadTranslationTable{
  ["lvs__chitu"] = "赤兔",
  ["#lvs__chitu_skill"] = "赤兔",
  [":lvs__chitu"] = "装备牌·进攻类坐骑<br /><b>坐骑技能</b>：锁定技，你与其他角色的距离-1；你使用♥【杀】不可被响应，若你的装备区内有武器牌，改为红色。",
}

local WhitehorseSkill = fk.CreateDistanceSkill{
  name = "#lvs__whitehorse_skill",
  attached_equip = "lvs__whitehorse",
  correct_func = function(self, from, to)
    local n = 0
    if from:hasSkill(self) and from.hp > 2 then
      n = n - 1
    end
    if to:hasSkill(self) then
      n = n + 1
    end
    return n
  end,
}

local Whitehorse = fk.CreateDefensiveRide{
  name = "lvs__whitehorse",
  suit = Card.Club,
  number = 1,
  equip_skill = WhitehorseSkill,
}
Fk:addSkill(WhitehorseSkill)
extension:addCards({
  Whitehorse,
})

Fk:loadTranslationTable{
  ["lvs__whitehorse"] = "白马",
  ["#lvs__whitehorse_skill"] = "白马",
  [":lvs__whitehorse"] = "装备牌·防御类坐骑<br /><b>坐骑技能</b>：锁定技，其他角色与你的距离+1，若你的体力值不小于2，你与其他角色的距离-1。",
}

local present = fk.CreateActiveSkill{
  name = "lvshi__present",
  target_num = 1,
  target_filter = function(self, to_select, selected, _, _, _, player)
    return to_select ~= player.id and #selected == 0
  end,
  on_use = function(self, room, effect)
    local id = effect.cards[1]
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = Fk:getCardById(id)
    if card:getTypeString() == "equip" then
      U.moveCardIntoEquip(room, target, id, self.name, true, player)
    else
      room:obtainCard(target, id, true, fk.ReasonGive)
    end
  end
}

Fk:addSkill(present)

local lvs__war_elephantSkill = fk.CreateDistanceSkill{
  name = "#lvs__war_elephant",
  attached_equip = "lvs__war_elephant",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if to:hasSkill(self) then
      return 2
    end
  end,
}

local elephant_trigger = fk.CreateTriggerSkill{
  name = "#lvs__war_elephant_trigger",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerEquip then
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide then
              return true
            end
          end
        end
      end
    end
  end,  
  on_cost = Util.TrueFunc, 
  on_use = function(self, event, target, player, data)
    local cards = player:getEquipments(Card.SubtypeDefensiveRide)
    player.room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
  end,
}

local elephant = fk.CreateDefensiveRide{
  name = "lvs__war_elephant",
  suit = Card.Spade,
  number = 11,
  equip_skill = lvs__war_elephantSkill,
  special_skills = { "lvshi__present" },
  on_install = function(self, room, player)
    local cards = player:getEquipments(Card.SubtypeOffensiveRide)
    if #cards > 0 then room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id) end
    DefensiveRide.onInstall(self, room, player)
  end,
  on_uninstall = function(self, room, player)
    DefensiveRide.onUninstall(self, room, player)
  end,
}

lvs__war_elephantSkill:addRelatedSkill(elephant_trigger)
Fk:addSkill(lvs__war_elephantSkill)
extension:addCards({
  elephant,
})

Fk:loadTranslationTable{
  ["lvs__war_elephant"] = "战象",
  ["#lvs__war_elephant"] = "战象",
  [":lvs__war_elephant"] = "装备牌·防御类坐骑<br /><b>坐骑技能</b>：锁定技，其他角色与你的距离+2。"..
  "<br />此牌置入你的装备区后，你弃置装备区内的进攻坐骑牌；当进攻坐骑牌置入你的装备区后，你弃置装备区内的此牌。",
  ["lvshi__present"] = "赠予",
  [":lvshi__present"] = "你可以将此牌交给一名其他角色，若为装备牌，改为置入其装备区。",
}

local CamelSkill = fk.CreateMaxCardsSkill{
  name = "#lvs__camel_maxcards",
  attached_equip = "lvs__camel",
  correct_func = function(self, player)
    if player:hasSkill(self) then
      return 2
    end
  end,
}

local Camel = fk.CreateDefensiveRide{
  name = "lvs__camel",
  suit = Card.Heart,
  number = 12,
  equip_skill = CamelSkill,
  special_skills = { "lvshi__present" },
}
Fk:addSkill(CamelSkill)
extension:addCard(Camel)

Fk:loadTranslationTable{
  ["lvs__camel"] = "骆驼",
  ["#lvs__camel_skill"] = "骆驼",
  [":lvs__camel"] = "装备牌·防御类坐骑<br /><b>坐骑技能</b>：锁定技，你的手牌上限+2。",
}

local wonder_mapSkill = fk.CreateTriggerSkill{
  name = "#lvshi__wonder_map_skill",
  attached_equip = "lvshi__wonder_map",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player.dead or player:getHandcardNum() >= 4 then return false end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip and Fk:getCardById(info.cardId).name == self.attached_equip then
            return self:isEffectable(player)
          end
        end
      end
    end
  end,
  on_use = function(self, event, _, player, data)
    local n = 4 - player:getHandcardNum()
    player:drawCards(n, "lvshi__wonder_map")
  end,
}

Fk:addSkill(wonder_mapSkill)

local wonder_map = fk.CreateTreasure{
  name = "lvshi__wonder_map",
  suit = Card.Heart,
  number = 8,
  equip_skill = wonder_mapSkill,
}

extension:addCard(wonder_map)

Fk:loadTranslationTable{
  ["lvshi__wonder_map"] = "天机图",
  [":lvshi__wonder_map"] = "装备牌·宝物<br /><b>宝物技能</b>：锁定技，你视为智勇策略角色；当你失去装备区内的【天机图】后，你将手牌补至四张。",
  ["#lvshi__wonder_map_skill"] = "天机图",
}

local secret_advanceSkill = fk.CreateActiveSkill{
  name = "lvshi__secret_advance_skill",
  prompt = "#lvshi__secret_advance",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = dismantlement.skill.modTargetFilter,
  target_filter = dismantlement.skill.targetFilter,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "lvshi__secret_advance", "secret_advance_scheme", "secret_advance_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    if player.dead or target.dead or target:isAllNude() then return end
    local n = 2
    if effect.extra_data.strategy == "secret_advance_scheme" then
      n = 4
    end
    local cards = room:askForCardsChosen(player, target, 1, n, "hej", "lvshi__secret_advance")
    room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, effect.from)
    if not player.dead and not (target.dead or player:isKongcheng()) then
      local n = math.min(#cards, player:getHandcardNum())
      local cards2 = room:askForCard(player, n, n, false, self.name, false, ".", "#secret_advance-return::"..effect.to..":"..n)
      room:moveCardTo(cards2, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, effect.from)
    end
    if effect.extra_data.strategy == "secret_advance_courage" then
      local targets = player:getTableMark("secret_advance-turn")
      table.insert(targets, effect.to)
      room:setPlayerMark(player, "secret_advance-turn", targets)
      room:handleAddLoseSkills(player, "#secret_advance_targetmod", nil, false, true)
    end
  end
}
local secret_advance = fk.CreateTrickCard{
  name = "lvshi__secret_advance",
  skill = secret_advanceSkill,
  suit = Card.Spade,
  number = 6,
}

local secret_advance_targetmod = fk.CreateTargetModSkill{
  name = "#secret_advance_targetmod",
  bypass_distances = function(self, player, skill, card, to)
    if card and to then
      local targetRecorded = player:getTableMark("secret_advance-turn")
      return table.contains(targetRecorded, to.id)
    end
  end,
}

Fk:addSkill(secret_advance_targetmod)

Fk:loadTranslationTable{
  ["lvshi__secret_advance"] = "暗度陈仓",
  ["#lvshi__secret_advance"] = "请选择一名区域内有牌的其他角色",
  [":lvshi__secret_advance"] = "<b>锦囊牌</b><br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名区域内有牌的其他角色<br /><b>效果</b>：你获得目标角色区域内一至两张牌，然后交给其等量的牌。"..
  "<br /><b>智策略效果</b>：获得牌的上限改为四张。<br /><b>勇策略效果</b>：你此回合对目标角色使用牌无距离限制。",
  ["secret_advance_scheme"] = "智策略",
  [":secret_advance_scheme"] = "获得牌的上限改为四张",
  ["secret_advance_courage"] = "勇策略",
  [":secret_advance_courage"] = "你此回合对目标角色使用牌无距离限制",
  ["#secret_advance-return"] = "请将%arg张牌交给%dest",
}

extension:addCard(secret_advance)

local unexpectationSkill = fk.CreateActiveSkill{
  name = "lvshi__unexpectation_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
    return to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  target_filter = Util.TargetFilter,
  on_use = function(self, room, use)
    local choice = strategytrickuse(room, use, "unexpectation", "unexpectation_scheme", "unexpectation_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    if target:isKongcheng() then return end
    local suit = effect.card.suit
    if effect.extra_data.strategy == "unexpectation_scheme" then
      local choice = room:askForChoice(player, {"log_spade", "log_heart", "log_club", "log_diamond"}, self.name)
      suit = U.ConvertSuit(choice, "sym", "int")
    end
    local card = room:askForCardChosen(player, target, "h", self.name)
    target:showCards(card)
    card = Fk:getCardById(card)
    if target.dead or card.suit == Card.NoSuit or suit == Card.NoSuit then return end
    if card.suit ~= suit then
      room:damage({
        from = player,
        to = target,
        card = effect.card,
        damage = 1,
        skillName = self.name
      })
    elseif effect.extra_data.strategy == "unexpectation_courage" then
      room:moveCardTo(card:getEffectiveId(), Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil)
    end
  end,
}

local unexpectation = fk.CreateTrickCard{
  name = "lvshi__unexpectation",
  skill = unexpectationSkill,
  suit = Card.Diamond,
  number = 1,
  is_damage_card = true,
}

Fk:addSkill(unexpectationSkill)
extension:addCard(unexpectation)

Fk:loadTranslationTable{
  ["lvshi__unexpectation"] = "出其不意",
  ["lvshi__unexpectation_skill"] = "出其不意",
  [":lvshi__unexpectation"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名有手牌的其他角色<br/><b>效果</b>：你选择目标角色的一张手牌，令其展示此牌，"..
  "若与此【出其不意】花色不同，你对其造成1点伤害。"..
  "<br /><b>智策略效果</b>：你指定此【出其不意】的花色。<br /><b>勇策略效果</b>：若花色相同，目标角色弃置展示的牌。",

  ["unexpectation_scheme"] = "智策略",
  [":unexpectation_scheme"] = "你指定此【出其不意】的花色",
  ["unexpectation_courage"] = "勇策略",
  [":unexpectation_courage"] = "若花色相同，目标角色弃置展示的牌",
}

local bladeSkill = fk.CreateTriggerSkill{
  name = "#lvshi__blade_skill",
  attached_equip = "lvshi__blade",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = player.room:getPlayerById(data.to)
    room:addPlayerMark(to, "@@lvshi__blade-turn")
    if data.card.suit == Card.Heart or (data.card.color == Card.Red and (player:getEquipment(Card.SubtypeDefensiveRide)
    or player:getEquipment(Card.SubtypeOffensiveRide))) then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
  end,
}

local blade_effect = fk.CreateProhibitSkill{
  name = "#lvshi__blade_effect",
  prohibit_use = function(self, player, card)
    if player:getMark("@@lvshi__blade-turn") > 0 and card then
      if card:isVirtual() then
        return table.find(card.subcards, function (id) return ls.isshown(Fk:getCardById(id)) end)
      else
        return ls.isshown(card)
      end
    end
  end,
}
bladeSkill:addRelatedSkill(blade_effect)
Fk:addSkill(bladeSkill)

local blade = fk.CreateWeapon{
  name = "lvshi__blade",
  suit = Card.Heart,
  number = 5,
  attack_range = 3,
  equip_skill = bladeSkill,
}

extension:addCards({
  blade,
})

Fk:loadTranslationTable{
  ["lvshi__blade"] = "偃月刀",
  ["@@lvshi__blade-turn"] = "偃月刀",
  [":lvshi__blade"] = "装备牌·武器<br /><b>攻击范围</b>：3 <br/><b>武器技能</b>：锁定技，你使用【杀】指定目标后，令目标角色于此回合不能使用明置牌；"..
  "你使用♥【杀】造成的伤害+1，若你的装备区内有坐骑牌，改为红色。",
  ["#lvshi__blade_skill"] = "偃月刀",
}


local lvshi__wooden_ox_skill = fk.CreateActiveSkill{
  name = "lvshi__wooden_ox_skill&",
  attached_equip = "lvshi__wooden_ox",
  prompt = "#lvshi__wooden_ox-prompt",
  can_use = function(self, player, card)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and #player:getPile("$role_carriage") < 5
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and table.contains(Self.player_cards[Player.Hand], to_select)
  end,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:addToPile("$role_carriage", effect.cards[1], false, self.name)
    if player.dead then return end
    local ox = table.find(player:getCardIds("e"), function (id) return Fk:getCardById(id).name == "lvshi__wooden_ox" end)
    if ox then
      local targets = table.filter(room.alive_players, function(p)
        return p ~= player and p:hasEmptyEquipSlot(Card.SubtypeTreasure) end)
      if #targets > 0 then
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#lvshi__wooden_ox-move", self.name, true)
        if #tos > 0 then
          room:moveCardTo(ox, Card.PlayerEquip, tos[1], fk.ReasonPut, self.name, nil, true, player.id, nil)
        end
      end
    end
  end,
}
local lvshi__wooden_ox_trigger = fk.CreateTriggerSkill{
  name = "#lvshi__wooden_ox_trigger",
  attached_equip = "lvshi__wooden_ox",
  mute = true,
  priority = 5,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:getPile("$role_carriage") == 0 then return false end
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if Fk:getCardById(info.cardId).name == "lvshi__wooden_ox" then
          --多个木马同时移动的情况取其中之一即可，不再做冗余判断
          if info.fromArea == Card.Processing then
            local room = player.room
            --注意到一次交换事件的过程中的两次移动事件都是在一个parent事件里进行的，因此查询到parent事件为止即可
            local move_event = room.logic:getCurrentEvent():findParent(GameEvent.MoveCards, true)
            local parent_event = move_event.parent
            local move_events = room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
              if e.id >= move_event.id or e.parent ~= parent_event then return false end
              for _, last_move in ipairs(e.data) do
                if last_move.moveReason == fk.ReasonExchange and last_move.toArea == Card.Processing then
                  return true
                end
              end
            end, parent_event.id)
            if #move_events > 0 then
              for _, last_move in ipairs(move_events[1].data) do
                if last_move.moveReason == fk.ReasonExchange then
                  for _, last_info in ipairs(last_move.moveInfo) do
                    if Fk:getCardById(last_info.cardId).name == "lvshi__wooden_ox" then
                      if last_move.from == player.id and last_info.fromArea == Card.PlayerEquip then
                        if move.toArea == Card.PlayerEquip then
                          if move.to ~= player.id then
                            self.cost_data = move.to
                            return true
                          end
                        else
                          self.cost_data = nil
                          return true
                        end
                      end
                    end
                  end
                end
              end
            end
          elseif move.moveReason == fk.ReasonExchange then
            if move.from == player.id and info.fromArea == Card.PlayerEquip and move.toArea ~= Card.Processing then
              --适用于被修改了移动区域的情况，如销毁，虽然说原则上移至处理区是不应销毁的
              self.cost_data = nil
              return true
            end
          elseif move.from == player.id and info.fromArea == Card.PlayerEquip then
            if move.toArea == Card.PlayerEquip then
              if move.to ~= player.id then
                self.cost_data = move.to
                return true
              end
            else
              self.cost_data = nil
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, _, player, data)
    local room = player.room
    local cards = player:getPile("$role_carriage")
    local to = self.cost_data
    if to then
      room:getPlayerById(to):addToPile("$role_carriage", cards, false, "lvshi__wooden_ox_skill&", nil, {player.id, to})
    else
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "lvshi__wooden_ox_skill&", nil, true)
    end
  end,
}
local lvshi__wooden_ox_filter = fk.CreateFilterSkill{
  name = "#lvshi__wooden_ox_filter",
  handly_cards = function (self, player)
    if player:hasSkill(lvshi__wooden_ox_skill) then
      return player:getPile("$role_carriage")
    end
  end,
}
lvshi__wooden_ox_skill:addRelatedSkill(lvshi__wooden_ox_trigger)
lvshi__wooden_ox_skill:addRelatedSkill(lvshi__wooden_ox_filter)
Fk:addSkill(lvshi__wooden_ox_skill)
local lvshi__wooden_ox = fk.CreateTreasure{
  name = "lvshi__wooden_ox",
  suit = Card.Club,
  number = 2,
  equip_skill = lvshi__wooden_ox_skill,

  on_uninstall = function(self, room, player)
    Treasure.onUninstall(self, room, player)
    player:setSkillUseHistory(self.equip_skill.name, 0, Player.HistoryPhase)
  end,
}
extension:addCard(lvshi__wooden_ox)
Fk:loadTranslationTable{
  ["lvshi__wooden_ox"] = "木牛流马",
  [":lvshi__wooden_ox"] = "装备牌·宝物<br/><b>宝物技能</b>：<br/>" ..
  "阶段技，你可将一张手牌扣置于装备区里的【木牛流马】下（称为“辎”，“辎”至多有5张），然后你可以将【木牛流马】置入一名"..
  "其他角色的装备区。你可以如手牌般使用或打出“辎”。",
  ["wooden_ox"] = "木牛流马",
  ["lvshi__wooden_ox_skill&"] = "木牛",
  [":lvshi__wooden_ox_skill&"] = "出牌阶段限一次，你可将一张手牌扣置于装备区里的【木牛流马】下（称为“辎”，“辎”至多有5张），"..
  "然后你可以将【木牛流马】置入一名其他角色的装备区。你可以如手牌般使用或打出“辎”。",
  ["#lvshi__wooden_ox-move"] = "你可以将【木牛流马】移动至一名其他角色的装备区",
  ["$role_carriage"] = "辎",
  ["#lvshi__wooden_ox_filter"] = "辎",
  ["#lvshi__wooden_ox_trigger"] = "木牛流马",
  ["#lvshi__wooden_ox-prompt"] = "你可以将一张手牌扣置于【木牛流马】下",
}

local shadeSkill = fk.CreateActiveSkill{
  name = "lvshi__shade_skill",
  can_use = Util.FalseFunc,
}

local shade = fk.CreateBasicCard{
  name = "&lvshi__shade",
  suit = Card.Spade,
  number = 1,
  skill = shadeSkill,
}

extension:addCard(shade)

Fk:loadTranslationTable{
  ["lvshi__shade"] = "影",
  [":lvshi__shade"] = "基本牌<br/><b>效果</b>：没有效果，不能被使用。<br/>当【影】进入弃牌堆后移出游戏。<br/>当一名角色获得【影】时，均为从游戏外获得♠A的【影】。",
}

local premeditate = fk.CreateDelayedTrickCard{  --祭祀智慧之不想带江山如故还引用蓄谋
  name = "&lvshi__premeditate",
}
extension:addCard(premeditate)
Fk:loadTranslationTable{
  ["premeditate"] = "蓄谋",
  ["lvshi__premeditate"] = "蓄谋",
  [":lvshi__premeditate"] = "这张牌视为延时锦囊<br/><b>效果：</b>判定阶段开始时，按置入顺序（后置入的先处理）依次处理“蓄谋”牌：1.使用此牌，"..
  "然后此阶段不能再使用此牌名的牌；2.将所有“蓄谋”牌置入弃牌堆。",
}

return extension